package com.jy.adscm.operation.job;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.base.bean.TaskManager;
import com.jy.adscm.operation.base.mapper.mysql.TaskManagerMapper;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmDateUtils;
import com.jy.adscm.utils.HttpRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author zyl
 * @Date 2019/1/31 -17:46
 * http://api.k780.com/?app=life.workday&date=20190204&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json.00
 */

public class TaskManagerJob {

 /*    @Autowired
    TaskManagerMapper  taskManagerMapper;
     @Autowired
    JyUserMapper  jyUserMapper;
    private Logger logger = Logger.getLogger(getClass());

       public void generateEveryDayTaskManager(){
         //查询当前时间是否工作日
             String formate = AdscmDateUtils.getNowOnlyDateFomat2(new Date());
             String s = HttpRequest.sendGet("http://api.k780.com/", "app=life.workday&date=" + formate + "&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json.00");
             JSONObject jsonObject = JSONObject.parseObject(s);
             String result = jsonObject.getJSONObject("result").getString("workmk");
             Date formateDate = AdscmDateUtils.getFormateDate(new Date());
             if ("1".equals(result)){
                 logger.info("今天是工作日");
                 Wrapper<JyUser> jyUserWrapper=new EntityWrapper<>();
                 jyUserWrapper.eq("enabled",1);
                 List<JyUser> jyUsers = jyUserMapper.selectList(jyUserWrapper);
                 for (JyUser jyUser : jyUsers) {
                     Wrapper<TaskManager> wrapper =new EntityWrapper<>();
                     wrapper.eq("performer",jyUser.getId());
                     wrapper.eq("creator",jyUser.getId());
                     wrapper.eq("finish_date",formateDate);
                     List<TaskManager> taskManagers = taskManagerMapper.selectList(wrapper);
                     logger.info(jyUser.getName()+"的每日任务"+taskManagers.size());
                     if (taskManagers.size()==0){
                         TaskManager taskManager =new TaskManager();
                         taskManager.setTaskName("每日任务");
                         taskManager.setCreateDate(new Date());
                         taskManager.setCreator(jyUser.getId().toString());
                         taskManager.setIsReceived("-1");
                         taskManager.setTaskResult("-1");
                         taskManager.setPerformer(jyUser.getId().toString());
                         taskManager.setDept(jyUser.getDeptId().toString());
                         taskManager.setFinishDate(formateDate);
                         taskManager.setStartDate(new Date());
                         taskManager.setStartCreateDate(new Date());
                         taskManager.setTaskSelfEvaluation("-1");
                         taskManager.setIsReviewTask("-1");
                         taskManager.setTaskState(1);
                         taskManager.setIsEveryDayTask("1");
                         taskManagerMapper.insert(taskManager);
                         logger.info(jyUser.getName()+"已经生成");
                     }
                 }
             }


       }*/

}
